package com.ruoyi.ruoyiqywechat.controller;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.qy.request.OrderPayRequest;
import com.ruoyi.common.qy.response.OrderPayResultResponse;
import com.ruoyi.common.qy.response.PayConfigResponse;
import com.ruoyi.common.qy.utils.CrmebUtil;
import com.ruoyi.ruoyiqywechat.service.OrderPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 支付管理
 */
@Slf4j
@RestController
@RequestMapping("api/front/pay")
//(tags = "支付管理")
public class PayController {

//    @Autowired
//    private WeChatPayService weChatPayService;

    @Autowired
    private OrderPayService orderPayService;



    //Operation(value = "获取支付配置")

    /**
     * 获取支付配置
     * @return
     */
    @RequestMapping(value = "/get/config", method = RequestMethod.GET)
    public R<PayConfigResponse> getPayConfig() {
        return R.ok(orderPayService.getPayConfig());
    }

    /**
     * 订单支付1
     */
    //Operation(value = "订单支付")
    @RequestMapping(value = "/payment", method = RequestMethod.POST)
    public R<OrderPayResultResponse> payment(@RequestBody @Validated OrderPayRequest orderPayRequest, HttpServletRequest request) {
        String ip = CrmebUtil.getClientIp(request);
        return R.ok(orderPayService.payment(orderPayRequest, ip));
    }

    /**
     * 查询支付结果
     *
     * @param orderNo |订单编号|String|必填
     */
    //Operation(value = "查询支付结果")
//    @RequestMapping(value = "/queryPayResult", method = RequestMethod.GET)
//    public CommonResult<Boolean> queryPayResult(@RequestParam String orderNo) {
//        return CommonResult.success(weChatPayService.queryPayResult(orderNo));
//    }
}
